import clonedeep from 'lodash.clonedeep'
export default {
  data() {
    return {
      tableData: [],
      // 双项绑定search
      searchForm: {},
      // 查询后存的search
      searchFormTemp: {},
      // 分页
      currentPage: 1,
      // 分页大小
      pageSize: 10,
      // 总条数
      total: 0,
      // 指定每页可以显示多少条
      pageSizeOptions: ['10', '20', '30', '40'],
      tableLoading: false
    }
  },
  methods: {
    // 重置
    resetForm(searchForm = {}) {
      this.searchForm = searchForm
      this.query(searchForm)
    },
    // 查询
    query(searchForm) {
      this.currentPage = 1
      this.searchFormTemp = clonedeep(searchForm)
      this.getTableData(searchForm)
    },
    // 当前页码变化
    onPageChange(pageNumber) {
      // console.log('Page: ', pageNumber)
      this.currentPage = pageNumber
      this.getTableData()
    },
    // 显示条数变化
    onSizeChange(current, size) {
      // console.log(size)
      this.currentPage = 1
      this.pageSize = size
      this.getTableData()
    }
  }
}
